jQuery(document).ready(function(){

	$j("#garbagegroup_handler").bind("click", function(){
		$j("#progress").fadeOut("fast");
		$j("#body").css({
			overflow: "hidden"	
		});
		window.scrollTo(0,0);
		$j("#deletegroup_box").fadeIn();	
	});

	$j("#modifygroups_handler").bind("click", function(){
		$j("#progress").fadeOut("fast");
		$j("#body").css({
			overflow: "hidden"	
		});
		window.scrollTo(0,0);
		$j("#modifygroup_box").fadeIn();	
	});
		

	
	$j("#close_gg").bind("click", function(){
		$j("#body").css({
			overflow: "auto"	
		});
		$j("#deletegroup_box").fadeOut();	
	});
	
	$j("#noticegg_not").bind("click", function(){
		$j("#body").css({
			overflow: "auto"	
		});
		$j("#deletegroup_box").fadeOut();		
	});
	
	$j("#close_mg").bind("click", function(){
		$j("#body").css({
			overflow: "auto"	
		});
		$j("#modifygroup_box").fadeOut();		
	});
	
	$j("#noticemg_not").bind("click", function(){
		$j("#body").css({
			overflow: "auto"	
		});
		$j("#modifygroup_box").fadeOut();		
	});
	
	$j("#noticemg_ok").bind("click", function(){
		
		var domains = $j("#modifygroups_form").attr("action");
		var paramss = $j("#groupsmg_chooser").attr("value");

		$j("#modifygroup_box").fadeOut();
		$j("#progress").fadeIn("slow");
		$j("#progress #pmessage").text("Please wait...");	
		setTimeout('document.location="'+domains+paramss+'"', 1000 );
		
	});
	
	$j("#noticegg_ok").bind("click", function(){	
		$j("#message_gg").text("Please wait... Garbage procedure is starting...");	
		
		var domain = $j("#garbagegroup_form").attr("action");
		var params = $j("#groupsgg_chooser").attr("value");
		
		$j.ajax({
			type: "POST",
			url:  domain+params,
			dataType: "json",
			error: function(){
					$j("#messagegg_box").addClass("error");
					$j("#messagegg_box").fadeIn("normal", function(){
						$j("#message_gg").text( "Ups... Some error with the script... Please contact community :/" );
					});	
			},
			success: function ( data, status ){
				
				if ( data.status == "false" )
				{
					$j("#messagegg_box").addClass("error");
					$j("#messagegg_box").fadeIn("normal", function(){
						$j("#message_gg").text( data.message );
					});

				}
				else if ( data.status == "true" )
				{
					$j("#messagegg_box").removeClass("error");
					$j("#messagegg_box").fadeIn("normal", function(){
						$j("#message_gg").text( data.message );
					});
					setTimeout('$j("#deletegroup_box").fadeOut("fast");location.reload(true);', 1000);
				}
				
			}
		});
		
	});
	
	
	$j("#noticeap_ok").bind("click", function(){	
		$j("#message").text("Please wait... Adding page procedure is starting...");	
		var group = $j("#groupspg_chooser").attr("value");
		var page  = $j("#addpage_input").attr("value");
		
	
		$j.ajax({
			type: "POST",
			url:  domain+"pages/add/validate/"+group+":"+page,
			dataType: "json",
			error: function(){
					$j("#messagegg_box").addClass("error");
					$j("#messagegg_box").fadeIn("normal", function(){
						$j("#message_gg").text( "Ups... Some error with the script... Please contact community :/" );
					});	
			},
			success: function ( data, status ){
				
				if ( data.status == "false" )
				{
					$j("#message_box").addClass("error");
					$j("#message_box").fadeIn("normal", function(){
						$j("#message").text( data.message );
					});

				}
				else if ( data.status == "true" )
				{
					$j("#message_box").removeClass("error");
					$j("#message_box").fadeIn("normal", function(){
						$j("#message").text( data.message );
					});
					setTimeout('$j("#addpage").fadeOut("fast");location.reload(true);', 1000);
				}
				
			}
		});
		
	});
	
	$j("#addpage_handler").bind("click", function(){	
		$j("#addpage").fadeIn("fast");
		$j("#addpage_input").attr("value", "") ;
	});
	
	$j("#close").bind("click", function(){	
		$j("#addpage").fadeOut("fast");
	});
	
	$j("#notice_not").bind("click", function(){	
		$j("#addpage").fadeOut("fast");
	});
});